package com.itheima.controller;

import com.itheima.domain.CheckItem;
import com.itheima.domain.PageBean;
import com.itheima.domain.R;
import com.itheima.service.CheckitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/checkitem")
public class CheckitemController {

    @Autowired
    private CheckitemService checkitemService;


    @PostMapping("/findPage")
    public Map<String,Object> findPage(@RequestBody PageBean pageBean){
        Map<String,Object> map = checkitemService.findPage(pageBean);
        return map;
    }

    @PostMapping("/add")
    public R addCheck(@RequestBody CheckItem checkItem){
        checkitemService.addCheck(checkItem);
        R r = new R();
        r.setMessage("新增检查项成功");
        return r;
    }

    @GetMapping("/delete")
    public R deleteCheck(Integer id){
        checkitemService.deleteCheck(id);
        R r = new R();
        r.setMessage("删除检查项成功");
        return r;
    }

    @GetMapping("/findById")
    public R getCheck(Integer id){
        CheckItem checkItem = checkitemService.getCheck(id);
        R r = new R();
        r.setData(checkItem);
        r.setMessage("查询检查项成功");
        return r;
    }

    @PostMapping("edit")
    public R updateCheck(@RequestBody CheckItem checkItem){
        checkitemService.updateCheck(checkItem);
        R r = new R();
        r.setMessage("编辑会员成功");
        return r;
    }

}
